import java.awt.geom.Point2D;
import java.awt.geom.AffineTransform;

public class Cuerpo
{
	int angulo, anguloAnterior;
	AffineTransform affineTransformPosicion, affineTransformVelocidad, affineTransformAceleracion;

	Cuerpo(int angulo, int x, int y)
	{
		this.angulo = angulo;
		this.anguloAnterior = angulo;
		this.affineTransformPosicion = new AffineTransform();
		this.affineTransformPosicion.translate(x, y);
		this.affineTransformVelocidad = new AffineTransform();
		this.affineTransformVelocidad.translate(0, 0);
		this.affineTransformAceleracion = new AffineTransform();
		this.affineTransformAceleracion.translate(0, -1);
	}

	int getAngulo()
	{
		return this.angulo;
	}

	int getX()
	{
		Point2D point2D = new Point2D.Double();
		point2D.setLocation(0, 0);
		point2D = this.affineTransformPosicion.transform(point2D, point2D);
		return (int)point2D.getX();
	}

	int getY()
	{
		Point2D point2D = new Point2D.Double();
		point2D.setLocation(0, 0);
		point2D = this.affineTransformPosicion.transform(point2D, point2D);
		return (int)point2D.getY();
	}

	void acelerar()
	{
		Point2D point2D = new Point2D.Double();
		point2D.setLocation(0, 0);
		point2D = this.affineTransformAceleracion.transform(point2D, point2D);
		this.affineTransformVelocidad.rotate(Math.toRadians(-this.anguloAnterior));
		this.affineTransformVelocidad.rotate(Math.toRadians(this.angulo));
		this.anguloAnterior = this.angulo;
		this.affineTransformVelocidad.translate(point2D.getX(), point2D.getY());
	}

	void corregirAngulo()
	{
		if (this.angulo < 0)
			this.angulo = 360 + this.angulo;
		else if (this.angulo > 359)
			this.angulo = this.angulo - 360;
	}

	void girarIzquierda()
	{
		this.angulo -= 5;
		corregirAngulo();
		this.affineTransformAceleracion.rotate(Math.toRadians(-5));
	}

	void girarDerecha()
	{
		this.angulo += 5;
		corregirAngulo();
		this.affineTransformAceleracion.rotate(Math.toRadians(5));
	}

	void voltear()
	{
		this.angulo += 180;
		corregirAngulo();
		this.affineTransformAceleracion.rotate(Math.toRadians(180));
	}

	void nuevaPosicion()
	{
		Point2D point2D = new Point2D.Double();
		point2D.setLocation(0, 0);
		point2D = this.affineTransformVelocidad.transform(point2D, point2D);
		this.affineTransformPosicion.translate(point2D.getX(), point2D.getY());
	}
}